import {defineStore} from 'pinia'
import {reactive} from "vue";
import {getApp} from "@/api/api.app";

export const AppStore = defineStore("app", () => {
    const app = reactive({
        name: '',
        avatar: '',
        id: ''
    });
    const setApp = (data: any) => {
        if (data) {
            Object.assign(app, data);
            app.avatar = app.name.charAt(0);
        }
    }

    const doLoadApp = async (id: any) => {
        await getApp({id}).then(res => {
            setApp(res.data || {});
        })
    }

    return {
        app,
        doLoadApp
    }
})
